package com.ls.resourceloader.antpathmatcher;

import org.springframework.util.AntPathMatcher;

import java.util.Map;

/**
 * AntPathMatcher[作用]:作urls路径匹配规则git
 * AntPathMatcher规则   ? 匹配一个字符 * 匹配0个或多个字符 **匹配0个或多个目录 可以带正则匹配的变量，如{spring:[a-z]+} , 变量名为spring
 * ，匹配正则式[a-z]+
 */
public class AntPathMatcherDemo {
	public static void main(String[] args) {
		AntPathMatcher matcher = new AntPathMatcher();

		//精准匹配
		System.out.println(matcher.match("/aa/bb/cc/a.text", "/aa/bb/cc/a.text"));
		//带"?"的匹配
		System.out.println(matcher.match("/aa/??/??/a.text", "/aa/bb/cc/a.text"));

		//带*的匹配
		System.out.println(matcher.match("/aa/*/*/a.text", "/aa/bb/cc/a.text"));
		//带**的匹配
		System.out.println(matcher.match("/aa/**/a.text", "/aa/bb/cc/a.text"));

		//带正则匹配的变量
		Map<String, String> map = matcher.extractUriTemplateVariables("/aa/bb/{path1}/{path2}/", "/aa/bb/cc/dd/");
		System.out.println(map);
	//正则 w+字母  d+数字
		map = matcher.extractUriTemplateVariables("/aa/bb/{path1:\\w+}/{path2:\\d+}/", "/aa/bb/cc/123/");
		System.out.println(map);
	}
}
